#include "FbxAnimationLayer.h"


namespace GC
{
	GC::FbxAnimationLayer::FbxAnimationLayer(FbxAnimLayer* a_animLayer, FbxNode* a_rootNode, const double a_deltaFrameTime)
	{
		HandleLayer( a_animLayer, a_rootNode, a_deltaFrameTime );
	}

	const GC::VectorFbxAnimationNodePtr GC::FbxAnimationLayer::GetNodes() const
	{
		return m_nodes;
	}
	const size_t GC::FbxAnimationLayer::GetNodesSize() const
	{
		return m_nodes.size();
	}
	/* Private functions */

	/// <summary>
	/// Recursively handles an animation layer by going through all the nodes, starts with the root node
	/// </summary>
	/// <param name="a_animLayer">The GC animation layer</param>
	/// <param name="a_node">The node to fetch animation data from</param>
	/// <param name="a_deltaFrameTime">The a_delta frame time.</param>
	void GC::FbxAnimationLayer::HandleLayer(FbxAnimLayer* a_animLayer, FbxNode* a_node, const double a_deltaFrameTime)
	{
		GC::FbxAnimationNodePtr f_animNode = std::make_shared<FbxAnimationNode>(a_animLayer,  a_node, a_deltaFrameTime );

		if (f_animNode->IsValid() )
		{
			m_nodes.push_back( f_animNode );
		}

		const int f_childCount = a_node->GetChildCount();
		for (int i = 0;i < f_childCount; ++i)
		{
			HandleLayer(a_animLayer, a_node->GetChild( i ), a_deltaFrameTime );
		}
	}
}
